-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for re-generating endpoints without restart #1146
Conversation
This feature is based on having either HotSwap Agent or JRebel set in the development environment for reloading classes so that Parser and Generator can re-generate the needed ts files based on the latest compiled classes. In this approach, a filesystem WatchService will start monitoring the classes directory (in a separate thread) for changes if: - Application is running in Dev mode, and - Dev mode live reload is enabled, and - The backend support for live reload is not Spring Boot DevTools When a change in the classes is detected, the Parser and then Generator will update the openapi.json, and since this file reside under classes itself, then its changes also detected which will trigger the re-registration of the Endpoints, without a need to restart the application. Limitations: The limitations are dictated by the limitations of JRebel or HotSwapAgent to redefining the classes at runtime. Some preliminary local tests shows that HotSwapAgent is working much smoother than JRebel. For example, JRebel sometimes fails to redefine the method renames in the memory, although, Hilla is reloading the change based on the latest changes completely fine. HowSwapAgent shows a faster reload as well compared to JRebel. If Only Spring Boot DevTools is in use in an application, the watch service will not register for changes, so the developer experience will not change. Developer, do not need to do any setup or changes to their project in order to enable this feature, other than setting up the HotSwapAgent or JRebel in their development environment.
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## main #1146 +/- ##
=======================================
Coverage 96.49% 96.49%
=======================================
Files 14 14
Lines 1657 1657
Branches 138 138
=======================================
Hits 1599 1599
Misses 58 58
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
packages/java/endpoint/src/main/java/dev/hilla/internal/hotswap/EndpointHotSwapListener.java
Show resolved
Hide resolved
packages/java/endpoint/src/main/java/dev/hilla/internal/hotswap/HotSwapConfiguration.java
Outdated
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Description
This feature is based on having either HotSwap Agent or JRebel set in the development environment for
reloading classes so that Parser and Generator can re-generate the needed TS files based on the latest compiled classes.
In this approach, an initiated service at startup polls for the changes of the endpoints and their associated classes, and by comparing the openapi contents with the previous state it will regenerate the needed TS files which makes them available to the views without restarting the application.
The polling service will start monitoring the changes (in a separate thread) if:
When a development environment meet the above criteria, the hot-reload feature is enabled by default. However, it can be disabled by setting the following property to false:
hilla.endpoint.hot-reload.enabled
The default monitoring poll interval is 5 seconds, which is configurable by setting the following property:
hilla.endpoint.hot-reload.pollInterval
Limitations:
The limitations are dictated by the limitations of JRebel or HotSwapAgent to redefining the classes at runtime. Some preliminary local tests shows that HotSwapAgent is working much smoother than JRebel. For example, JRebel sometimes fails to redefine the method renames in the memory, although, Hilla is reloading the change based on the latest changes completely fine. HowSwapAgent shows a faster reload as well compared to JRebel.
If Only Spring Boot DevTools is in use in an application, the watch service will not register for changes, so the developer experience will not change.
Developer, do not need to do any setup or changes to their project in order to enable this feature, other than setting up the HotSwapAgent or JRebel in their development environment.
Fixes #863
Type of change
Checklist
Additional for
Feature
type of change